﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.WinFormMVCFramework;
using TracyGUI.View;
using Microsoft.Practices.Unity;

namespace TracyGUI.Controller
{
    class PreferencesViewController : ControllerBase<IPreferencesView>, IController<IPreferencesView>
    {
        protected override IPreferencesView ResolveView()
        {
            return Tracy.TracyFacade.Instance.DIContainer.Resolve<IPreferencesView>();
        }

        public PreferencesViewController()
        {
            View.UserPreferencesChanging += new EventHandler<SharedLib.DataChangedEventArgs<Tracy.BasicServices.UserPreferencesManager.UserPreferences>>(View_UserPreferencesChanging);

            View.ApplyLanguage(Tracy.TracyFacade.Instance.LanguageManager);
            View.LoadUserPreferences(Tracy.TracyFacade.Instance.UserPreferencesManager.CurrentUserPreferences);

        }

        void View_UserPreferencesChanging(object sender, SharedLib.DataChangedEventArgs<Tracy.BasicServices.UserPreferencesManager.UserPreferences> e)
        {
            e.Data.FirstUseFlag = false;
            Tracy.TracyFacade.Instance.UserPreferencesManager.Update(e.Data);
        }
    }
}
